package org.tinaelle.exceptions;

import com.google.gwt.user.client.rpc.IsSerializable;

public class SerializableException extends RuntimeException implements
		IsSerializable {

	private static final long serialVersionUID = -971026567390218644L;

	private SerializableException cause = null;

	private String msg;

	public SerializableException() {
	}

	public SerializableException(String message) {
		this(message, null);
	}

	public SerializableException(String message, Throwable cause) {
		this(message, cause, true);
	}

	public SerializableException(String message, Throwable cause, boolean print) {
		msg = message;
		if (print) {
			printStackTrace();
			if (cause != null) {
				System.err.println("Caused by:");
				cause.printStackTrace();
			}
		}
		if (cause instanceof SerializableException)
			this.cause = (SerializableException) cause;
		else if (cause instanceof Throwable)
			this.cause = new SerializableException(cause.getMessage(), cause
					.getCause(), false);
	}

	public SerializableException(Throwable cause) {
		this(null, cause);
	}

	public Throwable getCause() {
		return cause;
	}

	public String getLocalizedMessage() {
		return msg;
	}

	public String getMessage() {
		return msg;
	}

	public String toString() {
		return "Exception " + msg;
	}
}
